package MVC.view;

import java.awt.Dimension;
import java.awt.FontMetrics;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;

public class ErrorBox extends JDialog implements ActionListener{

	private JPanel container = new JPanel(new GridLayout(2, 1, 20, 5));
	private JPanel panel = new JPanel();
	private JPanel panel2 = new JPanel();
	private JLabel label = null;
	private JButton quit = new JButton("Close"); 
	
	public ErrorBox(String name, String Message){
		this.setLocationRelativeTo(null);
		this.setResizable(false);
		//this.setSize(400, 120);
		this.pack();
		this.setTitle(name);
		this.label = new JLabel(Message);
		FontMetrics metrics = label.getFontMetrics(label.getFont());
		int messageWidth = metrics.stringWidth(label.getText());
		label.setSize(messageWidth,20);
		this.quit.setPreferredSize(new Dimension(70,30));
		this.quit.addActionListener(this);
		panel.add(label);
		panel2.add(quit);
		container.add(panel);
		container.add(panel2);
		this.setContentPane(container);
		this.pack();
		this.setVisible(true);
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		Object source = arg0.getSource();
        if (source.equals(quit)){
        	this.dispose();
        }
		
	}

	
}
